package com.future.direction.ui.activity;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.future.direction.R;
import com.future.direction.common.util.PopuUtil;
import com.future.direction.di.component.AppComponent;
import com.future.direction.ui.widget.MyPopupWindow;
import com.future.direction.ui.widget.MyTitleBar;

import butterknife.BindView;

/**
 * Created by zhp on 2019-11-08
 */
public class ConvertActivity extends BaseActivity implements View.OnClickListener {


    @BindView(R.id.titleBar)
    MyTitleBar titleBar;
    @BindView(R.id.et_convert_code)
    EditText etConvertCode;
    @BindView(R.id.button_convert_sure)
    Button buttonConvertSure;
    @BindView(R.id.ll_content)
    LinearLayout llContent;


    @Override
    public int setLayout() {
        return R.layout.activity_convert;
    }

    @Override
    public void getExtras() {

    }

    @Override
    public boolean init() {

        return false;
    }

    @Override
    public void setListener() {
        backListener(titleBar);
        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO 兑换记录
            }
        });
        etConvertCode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.toString().length() >= 1) {
                    buttonConvertSure.setEnabled(true);
                } else {
                    buttonConvertSure.setEnabled(false);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        buttonConvertSure.setOnClickListener(this);

    }

    @Override
    public void setupAcitivtyComponent(AppComponent appComponent) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button_convert_sure:
                //TODO 兑换码 请求成功后弹窗
                convertPopup();
                break;
        }
    }

    private void convertPopup() {
        MyPopupWindow convertPopupWindow = new PopuUtil().initAtLocationPopuWrap(this,
                R.layout.popup_convert, llContent, 311, 336);
        TextView tvConvertDate = convertPopupWindow.getContentView().findViewById(R.id.tv_convert_date);
        Button buttonConvertStudy = convertPopupWindow.getContentView().findViewById(R.id.button_convert_study);
        tvConvertDate.setText("截止日期：xxxx年xx月xx日");
        buttonConvertStudy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                convertPopupWindow.dismiss();
                //TODO 跳转到 学习页面
            }
        });
    }
}
